﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VCommons
{
    /// <summary>
    /// session 常用操作
    /// </summary>
    public  class SessionAction
    {
        #region 写入Session
        /// <summary>
        /// 写入Session
        /// </summary>
        /// <param name="name">Session名称</param>
        /// <param name="value">Session值</param>
        public static void WriteSession(string name, object value)
        {
            System.Web.HttpContext.Current.Session[name] = value;
        }
        #endregion

        #region 读取Session
        /// <summary>
        /// 读取Session
        /// </summary>
        /// <param name="name">Session名称</param>
        /// <returns>Session值</returns>
        public static string ReadSession(string name)
        {

            if (null != System.Web.HttpContext.Current.Session && null != System.Web.HttpContext.Current.Session[name])
            {
                return System.Web.HttpContext.Current.Session[name].ToString();
            }
            else
            {
                return "";
            }
        }
        #endregion

        #region 删除Session
        /// <summary>
        /// 删除Session
        /// </summary>
        /// <param name="name">Session名称</param>
        public static void ClearSession(string name)
        {
            System.Web.HttpContext.Current.Session.Remove(name);
        }
        #endregion
    }
}
